<?php
class Collection extends Eloquent
{
    public static $timestamps = false;

    public function numbers()
    {
        return $this->has_many('Number');
    }

    public static function getAll($id = null)
    {
        $query = static::with('numbers');
        if (!is_null($id))
        {
            $query = $query->where_id($id);
        }

        $data = array_map(function ($o) {
            return array(
                'id' => $o->id,
                'name' => $o->name,
                'numbers' => array_map(function ($numObject) {
                    return intval($numObject->number);
                }, $o->numbers)
            );
        }, $query->get());

        if (!is_null($id))
        {
            return $data[0];
        }
        else
        {
            return $data;
        }
    }
}